import myAxios from './myAxios'

// -----------用户api-----------
//获取菜单列表
export const reqMenuList = () => {
  let url = '/menus'
  return myAxios.get(url)
}
//根据id获取用户
export const reqUserById = (id) => {

  let url = `/users/${id}`
  return myAxios.get(url)
}
//获取用户列表
export const reqUserList = (queryInfo) => {
  let url = '/users'
  return myAxios.get(url, {
    params: {
      ...queryInfo
    }
  })
}
// 添加用户
export const reqAddUser = (addUserInfo) => {
  let url = '/users'
  return myAxios.post(url, {
    ...addUserInfo
  })
}
// 删除用户
export const reqDeleteUserById = (id) => {
  let url = `/users/${id}`
  return myAxios.delete(url)
}

// 修改用户
export const reqUpdateUser = (addUserInfo) => {
  let url = `/users/${addUserInfo.id}`
  return myAxios.put(url, {
    ...addUserInfo
  })
}

//更新用户状态
export const reqUpdateUserState = ({
  id,
  state
}) => {

  let url = `users/${id}/state/${state}`
  return myAxios.put(url)
}

//分配给用户角色
export const reqSetUserRole = (id, rid) => {

  let url = `users/${id}/role`
  return myAxios.put(url, {
    rid
  })
}
// -----------用户api结束-----------


// -----------权限api-----------

//获取权限列表
export const reqRightList = (type) => {

  let url = `/rights/${type}`
  return myAxios.get(url)
}
//获取角色列表
export const reqRolesList = () => {

  let url = `/roles`
  return myAxios.get(url)
}

// 根据id获取角色信息
export const reqRoleById = (id) => {
  let url = `/roles/${id}`
  return myAxios.get(url)
}
// 添加角色
export const reqAddRole = (roleInfo) => {
  let url = `/roles/`
  return myAxios.post(url, {
    ...roleInfo
  })
}

// 修改角色
export const reqUpdateRole = (roleInfo) => {
  let url = `/roles/${roleInfo.roleId}`
  return myAxios.put(url, {
    ...roleInfo
  })
}
// 删除角色
export const reqDeleteRoleById = (roleId) => {
  let url = `/roles/${roleId}`
  return myAxios.delete(url)
}
// 删除角色权限
export const reqDeleteRightById = (roleId, rightId) => {
  let url = `/roles/${roleId}/rights/${rightId}`
  return myAxios.delete(url)
}
// 删除角色权限
export const reqSetRoleRight = (roleId, rids) => {
  let url = `/roles/${roleId}/rights`
  return myAxios.post(url, {
    rids
  })
}

// -----------权限api结束-----------


// -----------商品api-----------

// 获取所有商品分类
export const reqCategory = (queryInfo) => {
  let url = `/categories`
  return myAxios.get(url, {
    params: {
      ...queryInfo
    }
  })
}


// 添加商品分类
export const reqAddCategory = (cateInfo) => {

  let url = `/categories`
  return myAxios.post(url, {
    ...cateInfo
  })
}
//根据id获取商品分类
export const reqCategoryById = (id) => {

  let url = `/categories/${id}`
  return myAxios.get(url)
}

// 修改分类
export const reqUpdateCate = (id, cat_name) => {
  let url = `/categories/${id}`
  return myAxios.put(url, {
    cat_name
  })
}

// 删除分类
export const reqDeleteCateById = (id) => {
  let url = `/categories/${id}`
  return myAxios.delete(url)
}
// -----------商品api结束-----------



// -----------分类参数api-----------

// 获取参数列表
export const reqParams = (id, sel) => {
  let url = `/categories/${id}/attributes`
  return myAxios.get(url, {
    params: {
      sel
    }
  })
}
// 添加动态参数或静态参数
export const reqAddParams = (paramsObj) => {
  let url = `/categories/${paramsObj.id}/attributes`
  return myAxios.post(url, {
    ...paramsObj
  })
}

// 根据id获取参数
export const reqParamsById = (paramsObj) => {
  let url = `/categories/${paramsObj.id}/attributes/${paramsObj.attrId}`
  return myAxios.get(url, {
    params: {
      ...paramsObj
    }
  })
}
// 根据id修改参数
export const reqUpdateParamsById = (paramsObj) => {
 
  let url = `/categories/${paramsObj.id}/attributes/${paramsObj.attrId}`
  return myAxios.put(url, {
    ...paramsObj
  })
}

// 根据id删除参数
export const reqDeleteParamsById = (paramsObj) => {
 
  let url = `/categories/${paramsObj.id}/attributes/${paramsObj.attrId}`
  return myAxios.delete(url)
}
